Ext.define('SKJF.view.PENJUALAN.v_do_form', {
	extend	: 'Ext.form.Panel',
	
	alias	: 'widget.v_do_form',
	
	//region:'east',
	//id: 'east-region-container',
	
	title		: 'Create/Update do',
    bodyPadding	: 5,
    autoScroll	: true,
    
    initComponent: function(){
    	/*
		 * Deklarasi variable setiap field
		 */
		
		var po_store = Ext.create('SKJF.store.s_poclient',{autoLoad:true});
		var currency_store = Ext.create('SKJF.store.s_mstcurrency',{autoLoad:true});
		var mstcustomer_store = Ext.create('SKJF.store.s_mstcustomer');
		
		var status_store = Ext.create('Ext.data.Store', {
			fields: ['value', 'display'],
			data : [
				{"value":"BELUM", "display":"BELUM"},
				{"value":"CICIL", "display":"CICIL"},
				{"value":"LUNAS", "display":"LUNAS"}
			]
		});
		
		var APA_KAPSUL_store = Ext.create('Ext.data.Store', {
			fields: ['value', 'display'],
			data : [{"value":"1", "display":"YA"},{"value":"0", "display":"TIDAK"}]
		});
		
		var NOMOR_DO_field = Ext.create('Ext.form.field.Hidden', {
			itemId: 'NOMOR_DO_field',
			name: 'NOMOR_DO', /* column name of table */
			fieldLabel: 'NOMOR_DO',
			allowBlank: true,
			readOnly: true
		});
		var TANGGAL_DO_field = Ext.create('Ext.form.field.Date', {
			name: 'TANGGAL_DO', /* column name of table */
			format: 'Y-m-d',
			fieldLabel: 'TANGGAL_DO',
			value : new Date()
		});
		var APA_KAPSUL_field = Ext.create('Ext.form.field.ComboBox', {
			name: 'APA_KAPSUL', /* column name of table */
			fieldLabel: 'APA_KAPSUL',
			store: APA_KAPSUL_store,
			queryMode: 'local',
			displayField: 'display',
			valueField: 'value'
		});
		var KODE_CUSTOMER_field = Ext.create('Ext.form.field.Hidden', {
			name: 'KODE_CUSTOMER', /* column name of table */
			fieldLabel: 'KODE_CUSTOMER',
			readOnly: true
		});
		var CONTACT_PERSON_field = Ext.create('Ext.form.field.Text', {
			name: 'CONTACT_PERSON', /* column name of table */
			fieldLabel: 'CONTACT_PERSON',
			readOnly: true
		});
		var ALAMAT_CUSTOMER_field = Ext.create('Ext.form.field.Text', {
			name: 'ALAMAT_CUSTOMER', /* column name of table */
			fieldLabel: 'ALAMAT_CUSTOMER',
			readOnly: true
		});
		var TELPON_CUSTOMER_field = Ext.create('Ext.form.field.Text', {
			name: 'TELPON_CUSTOMER', /* column name of table */
			fieldLabel: 'TELPON_CUSTOMER',
			readOnly: true
		});
		var FAX_CUSTOMER_field = Ext.create('Ext.form.field.Text', {
			name: 'FAX_CUSTOMER', /* column name of table */
			fieldLabel: 'FAX_CUSTOMER',
			readOnly: true
		});
		var NAMA_CUSTOMER_field = Ext.create('Ext.form.field.ComboBox', {
			inputId: 'NAMA_CUSTOMER',
			name: 'NAMA_CUSTOMER', /* column name of table */
			fieldLabel: 'NAMA_CUSTOMER',
			pageSize: 10,
			typeAhead    : true,
			triggerAction: 'all',
			selectOnFocus: true,
            loadingText  : 'Searching...',
			store: mstcustomer_store,
			queryMode: 'local',
			tpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'<div class="x-boundlist-item">{NAMA_CUSTOMER} - {TELPON}</div>',
				'</tpl>'
			),
			displayTpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'{NAMA_CUSTOMER} - {TELPON}',
				'</tpl>'
			),
			valueField: 'NAMA_CUSTOMER',
			displayField: 'NAMA_CUSTOMER',
			enableKeyEvents: true,
			listeners: {
				select: function(combo, records, e){
					KODE_CUSTOMER_field.setValue(records[0].data.KODE_CUSTOMER);
					CONTACT_PERSON_field.setValue(records[0].data.CONTACT_PERSON);
					ALAMAT_CUSTOMER_field.setValue(records[0].data.ALAMAT_1);
					TELPON_CUSTOMER_field.setValue(records[0].data.TELPON);
					FAX_CUSTOMER_field.setValue(records[0].data.FAX);
				}
			}
		});
		var NOMOR_PO_field = Ext.create('Ext.form.field.ComboBox', {
			itemId: 'NOMOR_PO_field',
			name: 'NOMOR_PO', /* column name of table */
			fieldLabel: 'NOMOR_PO',
			pageSize: 10,
			triggerAction: 'all',
			selectOnFocus: true,
            loadingText  : 'Searching...',
			store: po_store,
			queryMode: 'local',
			tpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'<div class="x-boundlist-item">{NOMOR_PO} - {NAMA_CUSTOMER}</div>',
				'</tpl>'
			),
			displayTpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'{NOMOR_PO} - {NAMA_CUSTOMER}',
				'</tpl>'
			),
			valueField: 'NOMOR_PO',
			displayField: 'NOMOR_PO',
			enableKeyEvents: true,
			listeners: {
				select: function(combo, records, e){
					var ns = records[0].data.NAMA_CUSTOMER;
					// NAMA_CUSTOMER_field.setValue(ns);
					mstcustomer_store.load({
						params: {
							NAMA_CUSTOMER: ns
						}
					});
				}
			}
		});
		var NOMOR_INVOICE_field = Ext.create('Ext.form.field.Hidden', {
			name: 'NOMOR_INVOICE', /* column name of table */
			fieldLabel: 'NOMOR_INVOICE',
			readOnly: true
		});
		var DRIVER_field = Ext.create('Ext.form.field.Text', {
			name: 'DRIVER', /* column name of table */
			fieldLabel: 'DRIVER',
			maxLength: 30 /* length of column name */
		});
		var NOMOR_VEHICLE_field = Ext.create('Ext.form.field.Text', {
			name: 'NOMOR_VEHICLE', /* column name of table */
			fieldLabel: 'NOMOR_VEHICLE'
		});
		var CURRENCY_field = Ext.create('Ext.form.field.ComboBox', {
			name: 'CURRENCY', /* column name of table */
			fieldLabel: 'CURRENCY',
			pageSize: 10,
			typeAhead    : true,
			triggerAction: 'all',
			selectOnFocus: true,
            loadingText  : 'Searching...',
			store: currency_store,
			queryMode: 'local',
			tpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'<div class="x-boundlist-item">{CURRENCY} - {NEGARA}</div>',
				'</tpl>'
			),
			displayTpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'{CURRENCY} - {NEGARA}',
				'</tpl>'
			),
			valueField: 'CURRENCY',
			displayField: 'CURRENCY'
		});
		var KURS_field = Ext.create('Ext.form.field.Hidden', {
			name: 'KURS', /* column name of table */
			fieldLabel: 'KURS',
			maxLength: 11,
			readOnly: true
		});
		var SUB_TOTAL_field = Ext.create('Ext.form.field.Hidden', {
			name: 'SUB_TOTAL', /* column name of table */
			fieldLabel: 'SUB_TOTAL',
			readOnly: true
		});
		var PPN_field = Ext.create('Ext.form.field.Number', {
			name: 'PPN', /* column name of table */
			fieldLabel: 'PPN',
			maxLength: 11 /* length of column name */
		});
		var MATERAI_field = Ext.create('Ext.form.field.Number', {
			name: 'MATERAI', /* column name of table */
			fieldLabel: 'MATERAI',
			maxLength: 11 /* length of column name */
		});
		var TOTAL_field = Ext.create('Ext.form.field.Hidden', {
			name: 'TOTAL', /* column name of table */
			fieldLabel: 'TOTAL',
			readOnly: true
		});
		var JATUH_TEMPO_field = Ext.create('Ext.form.field.Date', {
			name: 'JATUH_TEMPO', /* column name of table */
			format: 'Y-m-d',
			fieldLabel: 'JATUH_TEMPO'
		});
		var DIBUAT_OLEH_field = Ext.create('Ext.form.field.Text', {
			name: 'DIBUAT_OLEH', /* column name of table */
			fieldLabel: 'DIBUAT_OLEH',
			value : username,
			readOnly: true
		});
		var JUMLAH_EDIT_field = Ext.create('Ext.form.field.Hidden', {
			name: 'JUMLAH_EDIT', /* column name of table */
			fieldLabel: 'JUMLAH_EDIT',
			readOnly: true
		});
		var TANGGAL_EDIT_field = Ext.create('Ext.form.field.Hidden', {
			name: 'TANGGAL_EDIT', /* column name of table */
			format: 'Y-m-d',
			fieldLabel: 'TANGGAL_EDIT',
			value: new Date(),
			readOnly: true
		});
		var STATUS_field = Ext.create('Ext.form.field.ComboBox', {
			name: 'STATUS', /* column name of table */
			fieldLabel: 'STATUS',
			allowBlank: false,
			pageSize: 10,
			typeAhead    : true,
			triggerAction: 'all',
			selectOnFocus: true,
            loadingText  : 'Searching...',
			store: status_store,
			queryMode: 'local',
			tpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'<div class="x-boundlist-item">{display}</div>',
				'</tpl>'
			),
			displayTpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'{display}',
				'</tpl>'
			),
			valueField: 'value',
			displayField: 'display',
			value: 'BELUM'
		});
		var INFO_field = Ext.create('Ext.form.field.Text', {
			name: 'INFO', /* column name of table */
			fieldLabel: 'INFO',
			maxLength: 50 /* length of column name */
		});
		var POSTING_field = Ext.create('Ext.form.field.Text', {
			name: 'POSTING', /* column name of table */
			fieldLabel: 'POSTING'
		});		
        Ext.apply(this, {
            fieldDefaults: {
                labelAlign: 'right',
                labelWidth: 120,
                msgTarget: 'qtip',
				anchor: '100%'
            },
			defaultType: 'textfield',
            items: [NOMOR_DO_field,TANGGAL_DO_field,NOMOR_PO_field,APA_KAPSUL_field,NOMOR_INVOICE_field,KODE_CUSTOMER_field,NAMA_CUSTOMER_field,CONTACT_PERSON_field,ALAMAT_CUSTOMER_field,TELPON_CUSTOMER_field,FAX_CUSTOMER_field,JATUH_TEMPO_field,DRIVER_field,NOMOR_VEHICLE_field,CURRENCY_field,KURS_field,SUB_TOTAL_field,PPN_field,MATERAI_field,TOTAL_field,DIBUAT_OLEH_field,JUMLAH_EDIT_field,TANGGAL_EDIT_field,STATUS_field,INFO_field,POSTING_field],
			
	        buttons: [{
                iconCls: 'icon-save',
                itemId: 'save',
                text: 'Save',
                disabled: true,
                action: 'save'
            }, {
                iconCls: 'icon-add',
				itemId: 'create',
                text: 'Create',
                action: 'create'
            }, {
                iconCls: 'icon-reset',
                text: 'Cancel',
                action: 'cancel'
            }]
        });
        
        this.callParent();
    }
});